package com.neuedu.nas.back.casback.controller;

import com.neuedu.nas.back.casback.pojo.User;
import com.neuedu.nas.back.casback.pojo.com.CommonResult;
import com.neuedu.nas.back.casback.service.UserService;
import com.neuedu.nas.back.casback.service.impl.UserServiceServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping("/user")
//@Api
public class UserController {
    @Autowired
    UserServiceServiceImpl userService;

//    @ApiOperation("添加用户")
    @PostMapping("/insert")
    public CommonResult insert(User user){
        boolean insert = userService.insert(user);
        System.out.println(user);
        if (insert){
            return new CommonResult(200,"添加成功",insert);
        }else {
            return new CommonResult(404,"添加失败",insert);
        }

    }

    @GetMapping("/group")
    @ResponseBody
    public CommonResult groupUser(){
        List<User> lists=userService.groupUser();
        if (lists.size()>0){
            return new CommonResult(200,"查询成功",lists);
        }else {
            return new CommonResult(404,"查询失败",null);
        }
    }
    @GetMapping("/delete")
    public CommonResult deleteUser(@PathParam("id")Integer id){
        boolean b = userService.deleteUser(id);
        if (b){
            return new CommonResult(200,"删除成功",b);
        }else {
            return new CommonResult(404,"删除失败",b);
        }
    }

    @GetMapping("/update")
    public CommonResult updateUser(@PathParam("id")Integer id,
                              User user){
        boolean flg=userService.updateUser(id,user);
        if (flg){
            return new CommonResult(200,"更新成功",flg);
        }else {
            return new CommonResult(404,"更新失败",flg);
        }
    }



}
